/*************************************************************************************
 *
 *  Revolution Engine
 *  Copyright (C) 2009 Felipe Apablaza
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 ************************************************************************************/


//---------------------------------------------------------
//
//  File:	Thread.hpp
//  Desc:	Contain the thread states definitions, the 
//			"IThreaded" interface, and the "Thread" class.
//
//---------------------------------------------------------

#ifndef __REVENG_THREAD_HPP__
#define __REVENG_THREAD_HPP__

#include <RevEng/ObjRef.hpp>
#include <RevEng/IThread.hpp>

namespace RevEng
{
	class Thread
	{
	private:
		ObjRef<IThread> m_Ref;

	public:
		inline Thread()
		{
			m_Ref = static_cast<IThread*>(IObject::New( REVENG_THREAD ));
		}


		inline Thread(IThreaded *Threaded)
		{
			m_Ref = static_cast<IThread*>(IObject::New( REVENG_THREAD ));
			m_Ref->SetThreaded(Threaded);
		}

		inline void Start(void* Param)
		{
			m_Ref->Start(Param);
		}


		inline void Wait()
		{
			m_Ref->Wait();
		}


		inline void Abort()
		{
			m_Ref->Abort();
		}


		inline Enum GetStatus() const
		{
			return m_Ref->GetStatus();
		}


		inline void SetThreaded(IThreaded* Threaded)
		{
			m_Ref->SetThreaded(Threaded);
		}


		inline Int32 GetExitCode() const
		{
			return m_Ref->GetExitCode();
		}


		inline static void Yield()
		{
			IThread::Yield();
		}


		inline static void Sleep(Double secs)
		{
			IThread::Sleep(secs);
		}
	};
}

#endif	//__REVENG_THREAD_HPP__
